package com.jyw.business.ast.domain.dto.web;

import com.jyw.business.ast.constant.AstInfoEquipmentStateConstant;
import com.jyw.business.ast.domain.AstInfo;
import com.jyw.common.utils.DateUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.math.BigDecimal;

@Data
@ApiModel("资产-到期处置-请求实体")
public class AstExpireDisposeDto {
    @ApiModelProperty("id")
    private Long id;

    @ApiModelProperty("处置方式 1续用 2报废")
    private String dispose;

    @ApiModelProperty("续用周期")
    private Integer timer;

    @ApiModelProperty("续用周期单位 1年 2月 3周 4天")
    private String unit;

    public AstInfo buildInfo(){
        AstInfo info = new AstInfo();
        info.setId(getId());
        if(getDispose().equals("1")){
            info.setUseDate(DateUtils.getNowDate());
            info.setYears(BigDecimal.valueOf(getTimer()));
            info.setUseUnit(getUnit());
            info.setUseOverDate(DateUtils.calcAstDate(info.getUseDate(),info.getYears(),info.getUseUnit()));
        }else if(getDispose().equals("2")){
            info.setEquipmentState(AstInfoEquipmentStateConstant.SCRAP);
        }
        return info;
    }
}
